import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import CollapseTransition from "element-ui/lib/transitions/collapse-transition";
import './plugins/element.js'
import * as filters from './plugins/filter.js' //把所有filter输出包裹到obj对象里
// import Mock from './utils/mock'
// Mock.start();
console.log(process.env.VUE_APP_FLAG)
Vue.config.productionTip = false
Vue.use(ElementUI);
  Vue.prototype.setCookie = function (name, value, day) {
          if (day !== 0) { //当设置的时间等于0时，不设置expires属性，cookie在浏览器关闭后删除
              var curDate = new Date();
              var curTamp = curDate.getTime();
              var curWeeHours = new Date(curDate.toLocaleDateString()).getTime() - 1;
              var passedTamp = curTamp - curWeeHours;
              var leftTamp = 24 * 60 * 60 * 1000 - passedTamp;
              var leftTime = new Date();
              leftTime.setTime(leftTamp + curTamp);
              document.cookie = name + "=" + escape(value) + ";expires=" + leftTime.toGMTString();
          } else {
              document.cookie = name + "=" + escape(value);
          }
}
  Vue.prototype.getCookie = function (name) {
      var arr;
      var reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
      if (arr = document.cookie.match(reg))
          return unescape(arr[2]);
      else
          return null; ocument.cookie = name + "=" + escape(value);
      }
/*第一层if判断生产环境和开发环境*/
if (process.env.NODE_ENV === 'production') {
  /*第二层if，根据.env文件中的VUE_APP_FLAG判断是生产环境还是测试环境*/
  if (process.env.VUE_APP_FLAG === 'formal') {
      //formal 生产环境
      axios.defaults.baseURL = 'http://lele.daxunxun.com:9000/';

  } else {
      //test 测试环境
      axios.defaults.baseURL = 'http://localhost:7000/';

  }
} else {
  //dev 开发环境
  axios.defaults.baseURL = 'http://lele.daxunxun.com:9000/';
}

Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})
Vue.component(CollapseTransition.name, CollapseTransition);
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
